<?php
/* ----------------------------------------------------------
--               JacoCMS by Jaco Ruit                      --
-------------------------------------------------------------
--     JacoCMS is Open Source and is lincenced under       --
--             GNU General Public Licence v3               --
--          http://www.gnu.org/copyleft/gpl.html           --
-------------------------------------------------------------
--       Please don't remove any text from the footers.    --
-------------------------------------------------------------
-- Credits:   * Jaco Ruit          ~     Scripts,MySQL     --     
-----------------------------------------------------------*/

#important includes
include 'includes/config.php';
include 'includes/database.class.php'; 

#create database connection
$database = new Database();
$database->connect();

#finish includes
include 'includes/core.class.php';
include 'includes/article.class.php';
include 'includes/analytics.class.php';
include 'includes/settings.class.php';
include 'includes/page.class.php';

#vars, classes
$page = new Page();
$settings = new Settings();
$analytics = new Analytics();
$core = new Core();
$article = new Article();

#load style
$stylepath = $settings->loadStyle();
include ("style/" . $stylepath . "/styleinfo.php");

#settings
if ($settings->videoGalleryEnabled())
{
	$custom = $page->getMenuCode();
	$custom .= '<li><a href="videogallery">Video Gallery</a></li>';
}
else
{
	$custom = $page->getMenuCode();
}

#analytics
$analytics->logVisitor();

#get latest post
$rCount = $article->rowCount();
if($rCount == 0)
{
	$articlehtml = '<div id="error"><h3>No Articles To Display</h3><br /><p>You can add new articles at the admin panel</p></div>';
}
else if ($rCount == 1)
{
	$latestid = $article->getLastID();
	$latestpost = array();
	$latestpost = $article->getByID($latestid);
	$articlehtml = $article->getHTMLCode($latestpost);
	$articlehtml .= '<div id="center"><a href="archive">More posts..</a></p></div>';
}
else
{
	$latestid = $article->getLastID();
	$latestpost = array();
	$latestpost = $article->getByID($latestid);
	$idtwo = $latestid - 1;
	$latestpost2 = array();
	$latestpost2 = $article->getByID($idtwo);
	$articlehtml = $article->getHTMLCode($latestpost);
	$articlehtml .= $article->getHTMLCode($latestpost2);
	$articlehtml .= '<div id="center"><a href="archive">More posts..</a></p></div>';
}

#template
$smarty->assign("stylecss", $stylepath);
$smarty->assign("webname", $settings->getWebsiteName());
$smarty->assign("pagename", "Latest Posts");
$smarty->assign("articles", $articlehtml);
$smarty->assign("headertext", "Latest Posts");
$smarty->assign("stylename", $stylename);
$smarty->assign("styleauthor", $author);
$smarty->assign("authorwebsite", $authorwebsite);
$smarty->assign("custom", $custom);
$smarty->display("header.tpl");
$smarty->display("menu.tpl");
$smarty->display("index.tpl");
$smarty->display("footer.tpl");

?>
